<script setup lang="ts">

import ChatSetSvg from "@/svg/chatSetSvg.vue";
import ChatAnaSvg from "@/svg/chatAnaSvg.vue";
import ChatIconSvg from "@/svg/chatIconSvg.vue";
import router from "@/Router";
import {useRoute} from "vue-router";
import IconChatSumSvg from "@/svg/IconChatSumSvg.vue";
import type {typeUserChat} from "@/store/dataType";
import {findAllUserChatByAccountName} from "@/Network/chatApi";
import {ref} from "vue";
import {anaDataDate, anaDataSplitWord, anaDataTime} from "@/utils/anaData";
let route = useRoute()
let chatData = ref<typeUserChat[]>()
findAllUserChatByAccountName(localStorage.getItem("accountName")).then(res=>{
  chatData.value = res.data
})

async function toPage(key:string){
  //每次跳转都做一次，避免数据不一致。（使用的是老数据）
  let pageKey={
    key:key,
    chatData:null,
    chatCount:null,
    chatAnswerLength:null,
    chatQuestionLength:null,
  }
  if(key=="2"){
    router.push({
      path:"/chat",
      query:pageKey
    })
  }
  if(key=="3"){
    let data = await anaDataSplitWord(chatData.value, "question")

    pageKey.chatData = JSON.stringify(data)
    pageKey.chatCount = chatData.value?.length
    pageKey.chatQuestionLength = chatData.value.reduce((acc, curr) => acc + curr.question.length, 0);
    pageKey.chatAnswerLength = chatData.value.reduce((acc, curr) => acc + curr.answer.length, 0);
    router.push({
      path:"/chat_ana",
      query:pageKey
    })
  }
  if(key=="5"){
    pageKey.chatData = JSON.stringify(chatData.value)
    router.push({
      path:"/chat_sum",
      query:pageKey
    })
  }
  if(key=="4"){
    router.push({
      path:"/chat_setting",
      query:pageKey
    })
  }

}

</script>

<template>
  <el-menu
      class="el-menu-vertical-demo w-45 h-full "
      :default-active="route.query.key!=null ? route.query.key : '2'"
      style="
      --el-menu-text-color: rgb(128,128,128);
      /*--el-menu-hover-bg-color:transprant;*/
      --el-menu-hover-bg-color:#e9faf2;
      /*没生效 --el-menu-hover-text-color: #39c03a;*/

       --el-menu-active-color: #39c03a;
       border:0!important;
"
  >
    <el-menu-item index="2" @click="toPage(2)">
      <chat-icon-svg class="w-5 h-5 mr-2 ml-1"></chat-icon-svg>
      <span>开始对话</span>
    </el-menu-item>
    <el-menu-item index="5" @click="toPage(5)">
      <icon-chat-sum-svg class="w-5 h-5 mr-2 ml-1"></icon-chat-sum-svg>
      <span>对话统计</span>
    </el-menu-item>
    <el-menu-item index="3" @click="toPage(3)">
      <chat-ana-svg class="w-5 h-5 mr-2 ml-1"></chat-ana-svg>
      <span>对话分析</span>
    </el-menu-item>
    <el-menu-item index="4" @click="toPage(4)">
      <chat-set-svg class="w-5 h-5 mr-2 ml-1"></chat-set-svg>
      <span>设置</span>
    </el-menu-item>
  </el-menu>
</template>

<style scoped>

</style>